namespace DaoHang.Services
{
    /// <summary>
    /// 阿里云百炼AI服务接口
    /// </summary>
    public interface IAliCloudAIService
    {
        /// <summary>
        /// 总结网页内容
        /// </summary>
        /// <param name="url">网页URL</param>
        /// <param name="content">网页内容（可选）</param>
        /// <returns>总结结果</returns>
        Task<AISummaryResult> SummarizeWebContentAsync(string url, string? content = null);

        /// <summary>
        /// 生成网站描述
        /// </summary>
        /// <param name="title">网站标题</param>
        /// <param name="url">网站URL</param>
        /// <param name="content">网站内容</param>
        /// <returns>生成的描述</returns>
        Task<string> GenerateWebsiteDescriptionAsync(string title, string url, string? content = null);

        /// <summary>
        /// 智能分类建议
        /// </summary>
        /// <param name="websiteTitle">网站标题</param>
        /// <param name="websiteDescription">网站描述</param>
        /// <param name="websiteUrl">网站URL</param>
        /// <returns>分类建议</returns>
        Task<List<string>> SuggestCategoriesAsync(string websiteTitle, string websiteDescription, string websiteUrl);

        /// <summary>
        /// 生成网站内容摘要
        /// </summary>
        /// <param name="content">网站内容</param>
        /// <param name="url">网站URL</param>
        /// <returns>生成的摘要</returns>
        Task<string> GenerateSummaryAsync(string content, string url);

        /// <summary>
        /// 根据分类推荐网站
        /// </summary>
        /// <param name="categoryName">分类名称</param>
        /// <param name="categoryDescription">分类描述</param>
        /// <param name="existingWebsites">已有网站列表（用于避免重复推荐）</param>
        /// <param name="count">推荐数量</param>
        /// <param name="preferChineseWebsites">是否优先推荐中国网站</param>
        /// <returns>推荐的网站列表</returns>
        Task<List<RecommendedWebsite>> RecommendWebsitesByCategoryAsync(string categoryName, string? categoryDescription = null, List<string>? existingWebsites = null, int count = 20, bool preferChineseWebsites = true);

        /// <summary>
        /// 获取推荐网站（兼容方法名）
        /// </summary>
        /// <param name="categoryName">分类名称</param>
        /// <param name="categoryDescription">分类描述</param>
        /// <param name="count">推荐数量</param>
        /// <param name="preferChineseWebsites">是否优先推荐中国网站</param>
        /// <param name="existingUrls">已有网站URL列表</param>
        /// <returns>推荐的网站列表</returns>
        Task<List<RecommendedWebsite>> GetRecommendedWebsitesAsync(string categoryName, string? categoryDescription = null, int count = 20, bool preferChineseWebsites = true, List<string>? existingUrls = null) => 
            RecommendWebsitesByCategoryAsync(categoryName, categoryDescription, existingUrls, count, preferChineseWebsites);
    }

    /// <summary>
    /// AI总结结果
    /// </summary>
    public class AISummaryResult
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 总结内容
        /// </summary>
        public string Summary { get; set; } = string.Empty;

        /// <summary>
        /// 关键词
        /// </summary>
        public List<string> Keywords { get; set; } = new();

        /// <summary>
        /// 建议的分类
        /// </summary>
        public List<string> SuggestedCategories { get; set; } = new();

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorMessage { get; set; } = string.Empty;
    }

    /// <summary>
    /// AI推荐的网站
    /// </summary>
    public class RecommendedWebsite
    {
        /// <summary>
        /// 唯一标识符
        /// </summary>
        public string Id { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// 网站名称
        /// </summary>
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 网站URL
        /// </summary>
        public string Url { get; set; } = string.Empty;

        /// <summary>
        /// 网站描述（AI生成）
        /// </summary>
        public string Description { get; set; } = string.Empty;

        /// <summary>
        /// 推荐理由
        /// </summary>
        public string Reason { get; set; } = string.Empty;

        /// <summary>
        /// 图标URL（可选）
        /// </summary>
        public string? IconUrl { get; set; }

        /// <summary>
        /// 标签（逗号分隔）
        /// </summary>
        public string Tags { get; set; } = string.Empty;

        /// <summary>
        /// 推荐评分（1-10）
        /// </summary>
        public int Score { get; set; } = 5;

        /// <summary>
        /// 是否中国网站
        /// </summary>
        public bool IsChineseWebsite { get; set; } = false;

        /// <summary>
        /// 是否被用户选中保留
        /// </summary>
        public bool IsSelected { get; set; } = false;
    }
} 